//
//  CompanyHomeViewController.m
//  Logistics
//
//  Created by 华谕 on 2017/11/9.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "CompanyHomeViewController.h"
#import "SDCycleScrollView.h"
#import "DetailsModel.h"
#import "certificationModel.h"
#import "CDZStarsControl.h"
#import "ServiceSiteModel.h"
#import "CompanyImgModel.h"
#import "ComLineModel.h"
#import <MapKit/MapKit.h>
#import "MakeInquiryViewController.h"
#import "H5PublicViewController.h"
#import "CommentOfMineViewController.h"
#import "CredibilityViewController.h"

static NSString *cellPath = @"IntroductionCell";
static NSString *celladdressPath = @"addressCell";
static NSString *celljianjiePath = @"jianjieCell";
static NSString *cellphotoPath = @"photoCell";
@interface CompanyHomeViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,CDZStarsControlDelegate>
{
    UILabel *titLab;
    UIView *cerView;
    UIView *lineBottomV;
    UIButton *collectBtn;
    UIImage *logoimage;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
//@property (nonatomic, strong)CDZStarsControl *starsControl;

@property (nonatomic, assign)NSInteger infoType;
@property (nonatomic, strong)DetailsModel *detaModel;
@property (nonatomic, strong)certificationModel *cerModel;
@property (nonatomic, strong)NSArray *serviceAry;
@property (nonatomic, strong)NSArray *companyImgAry;
@property (nonatomic, strong)NSArray *companyLineAry;
@property (nonatomic, strong)NSMutableArray *vehicleLineAry;
@property (nonatomic, strong)NSMutableArray *LCLLineAry;
@property (nonatomic, strong)NSString *phoneString;
@property (nonatomic, strong)NSString *phoneName;

@end

@implementation CompanyHomeViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(callPhonesNotifice:) name:@"callPhones" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"callPhones" object:nil];
}


- (void)callPhonesNotifice:(NSNotification *)center
{
    NSString *timeStr = [center object];
    Student *stu = [Student studentWith:_detaModel.logo name:_phoneName Phone:_phoneString Times:timeStr];
    BOOL isInsert = [StudentFMDNManager addStudent:stu];
    
    if (isInsert) {
        NSLog(@"插入成功");
    } else {
        NSLog(@"插入失败");
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _infoType = 0;
    _vehicleLineAry = [NSMutableArray arrayWithCapacity:0];
    _LCLLineAry = [NSMutableArray arrayWithCapacity:0];
    [self creatUI];
    [self requestCompanyLine];
    [self requestCompanySelect];
    [self requestStatioFindByCompany];
    [self requestCompanyImg];
}

- (void)creatUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"公司详情";
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displayheight-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = RGB(245, 245, 245);
    [self.view addSubview:_tableview];
    UIView *heardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300*displayheight)];
    heardView.backgroundColor = [UIColor whiteColor];
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250*displayheight) delegate:self placeholderImage:nil];
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    _cycleScrollView.delegate = self;
    //是否自动轮播
    _cycleScrollView.autoScroll = YES;//是否自动轮播 bannerImageViewContentMode
    //图片样式
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.clipsToBounds = YES;
    //分页样式
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [heardView addSubview:_cycleScrollView];
    UIView *titView = [[UIView alloc] initWithFrame:CGRectMake(0, 215*displayheight, SCREEN_WIDTH, 35*displayheight)];
    titView.backgroundColor = RGBA(0, 0, 0, 0.7);
    [heardView addSubview:titView];
    
    titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, SCREEN_WIDTH-30*displaywidth, 35*displayheight) Font:19.0 Text:@"" Color:[UIColor whiteColor]];
    titLab.textAlignment = NSTextAlignmentLeft;
    [titView addSubview:titLab];
        
    cerView = [[UIView alloc] initWithFrame:CGRectMake(0, 250*displayheight, SCREEN_WIDTH, 40*displayheight)];
    cerView.backgroundColor = [UIColor whiteColor];
    [heardView addSubview:cerView];
    UIView *lines = [[UIView alloc] initWithFrame:CGRectMake(0, 290*displayheight, SCREEN_WIDTH, 10*displayheight)];
    lines.backgroundColor = RGB(245, 245, 245);
    [heardView addSubview:lines];
    _tableview.tableHeaderView = heardView;
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 50*displaywidth)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    UIButton *commentBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 7.5*displaywidth, SCREEN_WIDTH-200*displaywidth, 35*displaywidth) ImageName:@"db_nav4" Target:self Action:@selector(commentAction) Title:@" 我要评论" Font:13.0];
    commentBtn.layer.cornerRadius = 2;
    commentBtn.layer.masksToBounds = YES;
    commentBtn.backgroundColor = RGB(245, 245, 245);
    UIEdgeInsets imageViewEdge = UIEdgeInsetsMake(0, 10, 0, 0);
    [commentBtn setImageEdgeInsets:imageViewEdge];
    UIEdgeInsets titLabEdge = UIEdgeInsetsMake(0, 15, 0, 0);
    [commentBtn setTitleEdgeInsets:titLabEdge];
    commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    commentBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [commentBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
    [bottomView addSubview:commentBtn];
    NSArray *imgArray = @[@"db_nav1",@"db_nav2",@"db_nav3"];
    NSArray *titArray = @[@"官网",@"分享",@"询价"];
    NSArray *colorAry = @[RGB(0, 153, 255),RGB(0, 153, 0),RGB(255, 51, 51)];
    for (int i = 0; i < imgArray.count; i++)
    {
        UIButton *closebtn = [UIButton buttonWithType:UIButtonTypeCustom];
        closebtn.frame = CGRectMake(SCREEN_WIDTH-180*displaywidth+60*displaywidth*i, 0, 60*displaywidth, 50*displaywidth);
        [closebtn setImage:[UIImage imageNamed:imgArray[i]] forState:UIControlStateNormal];
        [closebtn setTitleColor:colorAry[i] forState:UIControlStateNormal];
        [closebtn setTitle:titArray[i] forState:UIControlStateNormal];
        closebtn.titleLabel.font = NormalFontWithSize(12.0+fontScale);
        closebtn.backgroundColor = [UIColor clearColor];
        closebtn.tag = 10+i;
        [closebtn addTarget:self action:@selector(itemBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [bottomView addSubview:closebtn];
        [self setButtonContentCenter:closebtn];
        if (i != 0)
        {
            UIView *lineBview = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-180*displaywidth+60*displaywidth*i, 12.5*displaywidth, 1, 25*displaywidth)];
            lineBview.backgroundColor = RGB(204, 204, 204);
            [bottomView addSubview:lineBview];
        }
        

    }
}

//我要评论
- (void)commentAction
{
    UserAccountModel *userModel = [UserAccountModel shareMange];
    if (![LTools storageForKey:SERVER_IsLogin])
    {
        [LTools showMBProgressWithText:@"请先登录" addToView:self.view];
        return;
    }
    if (userModel.isIdentify != 1)
    {
        [LTools showMBProgressWithText:@"请先实名认证" addToView:self.view];
        return;
    }
    CommentOfMineViewController *vc = [[CommentOfMineViewController alloc] init];
    vc.detaModel = _detaModel;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)setButtonContentCenter:(UIButton *) btn
{
    CGSize imgViewSize,titleSize,btnSize;
    UIEdgeInsets imageViewEdge,titleEdge;
    CGFloat heightSpace = 10.0f;
    
    //设置按钮内边距
    imgViewSize = btn.imageView.bounds.size;
    titleSize = btn.titleLabel.bounds.size;
    btnSize = btn.bounds.size;
    
    imageViewEdge = UIEdgeInsetsMake(heightSpace,0.0, btnSize.height -imgViewSize.height - heightSpace, - titleSize.width);
    [btn setImageEdgeInsets:imageViewEdge];
    titleEdge = UIEdgeInsetsMake(imgViewSize.height +heightSpace, - imgViewSize.width, 0.0, 0.0);
    [btn setTitleEdgeInsets:titleEdge];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_companyLineAry.count > 0 && _infoType == 2)
    {
        if (_vehicleLineAry.count > 0 && _LCLLineAry.count > 0)
        {
            return 2;
        }
    }
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_infoType == 0)
    {
         return _serviceAry.count;
    }
    if (_companyLineAry.count > 0 && _infoType == 2)
    {
        if (section == 0)
        {
            if (_vehicleLineAry.count > 0)
            {
                return _vehicleLineAry.count;
            }
            else
            {
                return _LCLLineAry.count;
            }
        }
        else
        {
            return _LCLLineAry.count;
        }
    }
    if (_infoType == 3)
    {
        return _companyImgAry.count;
    }
    if (_companyLineAry.count == 0 && _infoType == 2)
    {
        return _companyImgAry.count;
    }
    return 1;
}

-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = 10; //设置行间距
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
                          };
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    label.attributedText = attributeStr;
}

//计算UILabel的高度(带有行间距的情况)
-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = 10;
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
                          };
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        NSString *cellPathStr = celladdressPath;
        if (_infoType == 1)
        {
            cellPathStr = celljianjiePath;
        }
        if (_infoType == 2)
        {
            cellPathStr = cellPath;
        }
        if (_infoType == 3)
        {
            cellPathStr = cellphotoPath;
        }
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPathStr];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_infoType == 0)
    {
        cell.backgroundColor = BacksColor;
        ServiceSiteModel *model = _serviceAry[indexPath.row];
        UIView *backWhiteView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 170*displaywidth)];
        backWhiteView.backgroundColor = [UIColor whiteColor];
        backWhiteView.layer.cornerRadius = 10;
        backWhiteView.layer.masksToBounds = YES;
        [cell.contentView addSubview:backWhiteView];
        UIImageView *bqImgView = [ZCControl createImageViewWithFrame:CGRectMake(10*displaywidth, 20*displaywidth, 120*displaywidth, 35*displaywidth) ImageName:@"gs_icon04"];
        bqImgView.contentMode = UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:bqImgView];
        UILabel *stationNameLab = [ZCControl createLabelWithFrame:CGRectMake(30*displaywidth, 20*displaywidth, 200*displaywidth, 30*displaywidth) Font:15.0 Text:model.stationName Color:[UIColor whiteColor]];
        [cell.contentView addSubview:stationNameLab];
        UILabel *distanceLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH- 200*displaywidth, 10*displaywidth, 100*displaywidth, 30*displaywidth) Font:12.0 Text:model.distanceWithUnit Color:BlaTitColor];
        distanceLab.textAlignment = NSTextAlignmentRight;
        [backWhiteView addSubview:distanceLab];
        UIButton *pushMap = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 10*displaywidth, 70*displaywidth, 30*displaywidth) ImageName:@"gs_icon0511" Target:self Action:@selector(pushMapAction:) Title:@" 导航" Font:12.0];
        [pushMap setTitleColor:ThemeColor forState:UIControlStateNormal];
        pushMap.tag = indexPath.row + 200;
        [backWhiteView addSubview:pushMap];
        NSArray *imageAry = @[@"lb_icon08",@"lb_icon09",@"lb_icon10"];
        NSArray *contAry = @[model.address,[NSString stringWithFormat:@"业务咨询：%@%@",model.name,model.phone],string(@"售后热线：", model.fixPhone)];
        CGFloat h = 50*displaywidth;
        for (int i = 0; i < imageAry.count; i++)
        {
            UIImageView *leftImgview = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, h+5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:imageAry[i]];
            leftImgview.contentMode = UIViewContentModeScaleAspectFit;
            [backWhiteView addSubview:leftImgview];
            UILabel *rightLab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, h, SCREEN_WIDTH-100*displaywidth, 25*displaywidth) Font:15.0 Text:contAry[i] Color:RGB(51, 51, 51)];
            rightLab.textAlignment = NSTextAlignmentLeft;
            [backWhiteView addSubview:rightLab];
            if (i == 0)
            {
                CGRect bounds = [rightLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-100*displaywidth, 300) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
                if (bounds.size.height > 25*displaywidth)
                {
                    rightLab.frame = CGRectMake(35*displaywidth, h, SCREEN_WIDTH-100*displaywidth, bounds.size.height+10*displaywidth);
                    h+= bounds.size.height+20*displaywidth;
                }
                else
                {
                    h += 35*displaywidth;
                }
            }
            else
            {
                if (i == 1)
                {
                    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:contAry[i]];
                    NSRange titleRange = [[title string]rangeOfString:[NSString stringWithFormat:@"%@",model.phone]];
                    [title addAttribute:NSForegroundColorAttributeName value:ThemeColor range:titleRange];
                    [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
                    rightLab.attributedText = title;
                    UIButton *callPhone = [ZCControl createButtonWithFrame:CGRectMake(35*displaywidth, h, SCREEN_WIDTH-100*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(callPgoneAction:) Title:nil Font:12.0];
                    callPhone.backgroundColor = [UIColor clearColor];
                    callPhone.tag = (indexPath.row+1)*1000+i;
                    [backWhiteView addSubview:callPhone];
                }
                else
                {
                    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:contAry[i]];
                    NSRange titleRange = [[title string]rangeOfString:[NSString stringWithFormat:@"%@",model.fixPhone]];
                    [title addAttribute:NSForegroundColorAttributeName value:ThemeColor range:titleRange];
                    [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
                    rightLab.attributedText = title;
                }
                h += 35*displaywidth;
            }
        }
        backWhiteView.frame = CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, h);
        
    }
    else if (_infoType == 1)
    {
        if (_detaModel)
        {
            cell.backgroundColor = BacksColor;
            UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 55*displaywidth) Font:15.0 Text:string(@" 主营: ", _detaModel.sketch) Color:RGB(255, 153, 0)];
            titLab.backgroundColor = [UIColor whiteColor];
            titLab.layer.cornerRadius = 5;
            titLab.layer.masksToBounds = YES;
            [cell.contentView addSubview:titLab];
            UILabel *jianjieLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 75*displayheight, SCREEN_WIDTH-30*displaywidth, 120*displaywidth) Font:15.0 Text:[NSString stringWithFormat:@"       %@",_detaModel.describes] Color:RGB(51, 51, 51)];
            jianjieLab.numberOfLines = 0;
            [self setLabelSpace:jianjieLab withValue:[NSString stringWithFormat:@"       %@",_detaModel.describes] withFont:NormalFontWithSize(15.0+fontScale)];
            CGFloat height = [self getSpaceLabelHeight:[NSString stringWithFormat:@"       %@",_detaModel.describes] withFont:NormalFontWithSize(15.0+fontScale) withWidth:SCREEN_WIDTH-30*displaywidth];
            [cell.contentView addSubview:jianjieLab];
//            CGRect bounds = [jianjieLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30*displaywidth, 20000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            jianjieLab.frame = CGRectMake(15*displaywidth, 75*displayheight, SCREEN_WIDTH-30*displaywidth, height+20*displaywidth);
            UIImageView *bottomImgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, height+110*displaywidth, SCREEN_WIDTH-30*displaywidth, 250*displaywidth) ImageName:nil];
            [bottomImgView sd_setImageWithURL:[NSURL URLWithString:_detaModel.price] placeholderImage:[UIImage imageNamed:@"newsImage"]];
            bottomImgView.contentMode = UIViewContentModeScaleAspectFill;
            bottomImgView.layer.masksToBounds = YES;
            [cell.contentView addSubview:bottomImgView];
            

        }
    }
    else if (_infoType == 2 && _companyLineAry.count > 0)
    {
        cell.backgroundColor = BacksColor;
        if (indexPath.section == 0 && _vehicleLineAry.count > 0)
        {
            ComLineModel *model = _vehicleLineAry[indexPath.row];
            CGFloat H = 0;
            if (indexPath.row == 0)
            {
                H = 80*displaywidth;
                UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(25*displaywidth, 10*displaywidth, SCREEN_WIDTH-50*displaywidth, 20*displaywidth) Font:13.0 Text:@"温馨提示：此价格仅供参考，实际运费以电话咨询为准。" Color:RGB(102, 102, 102)];
                [cell.contentView addSubview:tostLab];
                UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 40*displaywidth, SCREEN_WIDTH-30*displaywidth, 40*displaywidth)];
                topView.backgroundColor = [UIColor whiteColor];
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:topView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
                CAShapeLayer *layer = [[CAShapeLayer alloc]init];
                layer.frame = topView.bounds;
                layer.path = maskPath.CGPath;
                topView.layer.mask = layer;
                [cell.contentView addSubview:topView];
                UIImageView *bqImgView = [ZCControl createImageViewWithFrame:CGRectMake(10*displaywidth, 50*displaywidth, 120*displaywidth, 35*displaywidth) ImageName:@"gs_icon04"];
                bqImgView.contentMode = UIViewContentModeScaleAspectFit;
                [cell.contentView addSubview:bqImgView];
                UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(30*displaywidth, 50*displaywidth, 200*displaywidth, 30*displaywidth) Font:15.0 Text:@"整车运价" Color:[UIColor whiteColor]];
                [cell.contentView addSubview:typeLab];
            }
            UIView *whiteAView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, H, SCREEN_WIDTH-30*displaywidth, 70*displaywidth)];
            whiteAView.backgroundColor = [UIColor whiteColor];
            if (indexPath.row == _vehicleLineAry.count-1)
            {
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:whiteAView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
                CAShapeLayer *layer = [[CAShapeLayer alloc]init];
                layer.frame = whiteAView.bounds;
                layer.path = maskPath.CGPath;
                whiteAView.layer.mask = layer;
            }
            else
            {
                UIView *lineAview = [[UIView alloc] initWithFrame:CGRectMake(5*displaywidth, 69*displaywidth, SCREEN_WIDTH-40*displaywidth, 1*displaywidth)];
                lineAview.backgroundColor = LinesColor;
                [whiteAView addSubview:lineAview];
            }
            [cell.contentView addSubview:whiteAView];
            UILabel *startLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, 100*displaywidth, 25*displaywidth) Font:15.0 Text:model.shipmentName Color:BlaTitColor];
            startLab.textAlignment = NSTextAlignmentLeft;
            [whiteAView addSubview:startLab];
            CGRect bound1 = [startLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            CGFloat W = bound1.size.width+10*displaywidth;
            startLab.frame = CGRectMake(15*displaywidth, 10*displaywidth, W, 25*displaywidth);
            W+=15*displaywidth;
            UIImageView *zhiXimgView = [ZCControl createImageViewWithFrame:CGRectMake(W, 17.5*displaywidth, 30*displaywidth, 10*displaywidth) ImageName:@"zxli_icon01"];
            zhiXimgView.contentMode = UIViewContentModeScaleAspectFit;
            [whiteAView addSubview:zhiXimgView];
            W+=40*displaywidth;
            UILabel *stopLab = [ZCControl createLabelWithFrame:CGRectMake(W, 10*displaywidth, 100*displaywidth, 25*displaywidth) Font:15.0 Text:model.destinationname Color:BlaTitColor];
            stopLab.textAlignment = NSTextAlignmentLeft;
            [whiteAView addSubview:stopLab];
            CGRect bound2 = [stopLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            stopLab.frame = CGRectMake(W, 10*displaywidth, bound2.size.width+10*displaywidth, 25*displaywidth);
            UIImageView *carImgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 40*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"lb_icon32"];
            carImgView.contentMode = UIViewContentModeScaleAspectFit;
            [whiteAView addSubview:carImgView];
            UILabel *lenthLab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 35*displaywidth, SCREEN_WIDTH-80*displaywidth, 25*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"%@米/%@   ￥%@元左右",model.length,model.truckType,model.price] Color:BlaTitColor];
            NSMutableAttributedString *hintString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@米/%@   ￥%@元左右",model.length,model.truckType,model.price]];
            //获取要调整颜色的文字位置,调整颜色
            NSRange range1 = [[hintString string]rangeOfString:[NSString stringWithFormat:@"￥%@元左右",model.price]];
            [hintString addAttribute:NSForegroundColorAttributeName value:RGB(230, 67, 64) range:range1];
            lenthLab.attributedText = hintString;
            [whiteAView addSubview:lenthLab];
            NSString *str = [self timeIntervalFromLastTime:model.createDtm lastTimeFormat:@"yyyy-MM-dd HH:mm:ss"];
            UILabel *timeLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-120*displaywidth, 10*displaywidth, 75*displaywidth, 25*displaywidth) Font:12.0 Text:str Color:RGB(153, 153, 153)];
            timeLab.textAlignment = NSTextAlignmentRight;
            [whiteAView addSubview:timeLab];
            
        }
        else
        {
            ComLineModel *model = _LCLLineAry[indexPath.row];
            CGFloat H = 0;
            if (indexPath.row == 0)
            {
                H = 50*displaywidth;
                UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 40*displaywidth)];
                topView.backgroundColor = [UIColor whiteColor];
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:topView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
                CAShapeLayer *layer = [[CAShapeLayer alloc]init];
                layer.frame = topView.bounds;
                layer.path = maskPath.CGPath;
                topView.layer.mask = layer;
                [cell.contentView addSubview:topView];
                UIImageView *bqImgView = [ZCControl createImageViewWithFrame:CGRectMake(10*displaywidth, 20*displaywidth, 120*displaywidth, 35*displaywidth) ImageName:@"gs_icon04"];
                bqImgView.contentMode = UIViewContentModeScaleAspectFit;
                [cell.contentView addSubview:bqImgView];
                UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(30*displaywidth, 20*displaywidth, 200*displaywidth, 30*displaywidth) Font:15.0 Text:@"零担运价" Color:[UIColor whiteColor]];
                [cell.contentView addSubview:typeLab];
            }
            UIView *whiteAView = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, H, SCREEN_WIDTH-30*displaywidth, 85*displaywidth)];
            whiteAView.backgroundColor = [UIColor whiteColor];
            if (indexPath.row == _LCLLineAry.count-1)
            {
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:whiteAView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
                CAShapeLayer *layer = [[CAShapeLayer alloc]init];
                layer.frame = whiteAView.bounds;
                layer.path = maskPath.CGPath;
                whiteAView.layer.mask = layer;
            }
            else
            {
                UIView *lineAview = [[UIView alloc] initWithFrame:CGRectMake(5*displaywidth, 84*displaywidth, SCREEN_WIDTH-40*displaywidth, 1*displaywidth)];
                lineAview.backgroundColor = LinesColor;
                [whiteAView addSubview:lineAview];
            }
            [cell.contentView addSubview:whiteAView];
            UILabel *startLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, 100*displaywidth, 25*displaywidth) Font:15.0 Text:model.shipmentName Color:BlaTitColor];
            startLab.textAlignment = NSTextAlignmentLeft;
            [whiteAView addSubview:startLab];
            CGRect bound1 = [startLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            CGFloat W = bound1.size.width+10*displaywidth;
            startLab.frame = CGRectMake(15*displaywidth, 10*displaywidth, W, 25*displaywidth);
            W+=15*displaywidth;
            UIImageView *zhiXimgView = [ZCControl createImageViewWithFrame:CGRectMake(W, 17.5*displaywidth, 30*displaywidth, 10*displaywidth) ImageName:@"zxli_icon01"];
            zhiXimgView.contentMode = UIViewContentModeScaleAspectFit;
            [whiteAView addSubview:zhiXimgView];
            W+=40*displaywidth;
            UILabel *stopLab = [ZCControl createLabelWithFrame:CGRectMake(W, 10*displaywidth, 100*displaywidth, 25*displaywidth) Font:15.0 Text:model.destinationname Color:BlaTitColor];
            stopLab.textAlignment = NSTextAlignmentLeft;
            [whiteAView addSubview:stopLab];
            CGRect bound2 = [stopLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            stopLab.frame = CGRectMake(W, 10*displaywidth, bound2.size.width+10*displaywidth, 25*displaywidth);
            UILabel *puLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 37.5*displaywidth, 15*displaywidth, 15*displaywidth) Font:10 Text:@"普" Color:[UIColor whiteColor]];
            puLab.textAlignment = NSTextAlignmentCenter;
            puLab.backgroundColor = ThemeColor;
            puLab.layer.cornerRadius = 2;
            puLab.layer.masksToBounds = YES;
            [whiteAView addSubview:puLab];
            UILabel *lenthLab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 35*displaywidth, SCREEN_WIDTH-80*displaywidth, 20*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"￥%@元/吨   ￥%@元/方  %@天",model.pHeavyPrice,model.pLowPrice,model.pTimeBar] Color:BlaTitColor];
            NSMutableAttributedString *hintString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%@元/吨   ￥%@元/方  %@天",model.pHeavyPrice,model.pLowPrice,model.pTimeBar]];
            //获取要调整颜色的文字位置,调整颜色
            NSRange range1 = [[hintString string]rangeOfString:[NSString stringWithFormat:@"￥%@",model.pHeavyPrice]];
            NSRange range2 = [[hintString string]rangeOfString:[NSString stringWithFormat:@"￥%@",model.pLowPrice]];
            [hintString addAttribute:NSForegroundColorAttributeName value:RGB(230, 67, 64) range:range1];
            [hintString addAttribute:NSForegroundColorAttributeName value:RGB(230, 67, 64) range:range2];
            lenthLab.attributedText = hintString;
            [whiteAView addSubview:lenthLab];
            
            UILabel *kuaiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 57.5*displaywidth, 15*displaywidth, 15*displaywidth) Font:10 Text:@"快" Color:[UIColor whiteColor]];
            kuaiLab.textAlignment = NSTextAlignmentCenter;
            kuaiLab.backgroundColor = RGB(255, 153, 0);
            kuaiLab.layer.cornerRadius = 2;
            kuaiLab.layer.masksToBounds = YES;
            [whiteAView addSubview:kuaiLab];
            UILabel *lenthBLab = [ZCControl createLabelWithFrame:CGRectMake(35*displaywidth, 55*displaywidth, SCREEN_WIDTH-80*displaywidth, 20*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"￥%@元/吨   ￥%@元/方  %@天",model.kHeavyPrice,model.kLowPrice,model.kTimeBar] Color:BlaTitColor];
            NSMutableAttributedString *hintBString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%@元/吨   ￥%@元/方  %@天",model.kHeavyPrice,model.kLowPrice,model.kTimeBar]];
            //获取要调整颜色的文字位置,调整颜色
            NSRange range3 = [[hintBString string]rangeOfString:[NSString stringWithFormat:@"￥%@",model.kHeavyPrice]];
            NSRange range4 = [[hintBString string]rangeOfString:[NSString stringWithFormat:@"￥%@",model.kLowPrice]];
            [hintBString addAttribute:NSForegroundColorAttributeName value:RGB(230, 67, 64) range:range3];
            [hintBString addAttribute:NSForegroundColorAttributeName value:RGB(230, 67, 64) range:range4];
            lenthBLab.attributedText = hintBString;
            [whiteAView addSubview:lenthBLab];
            
        }
    }
    else
    {
        [self confirmCell:cell atIndexPath:indexPath];
    }
    
    return cell;

}

- (void)confirmCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = BacksColor;
    CompanyImgModel *imgModel = _companyImgAry[indexPath.row];
    UIImageView *bigImgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 150*displaywidth) ImageName:@""];
    bigImgView.contentMode = UIViewContentModeScaleAspectFill;
    bigImgView.layer.masksToBounds = YES;
    [cell.contentView addSubview:bigImgView];
    UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 160*displaywidth, SCREEN_WIDTH-30*displaywidth, 35*displaywidth) Font:15.0 Text:imgModel.title Color:ThemeColor];
    nameLab.textAlignment = NSTextAlignmentCenter;
    [cell.contentView addSubview:nameLab];
    UIImage *cachedImg = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imgModel.img];
    if (!cachedImg) {
        [self downloadImage:imgModel.img forIndexPath:indexPath];
    }else{
        bigImgView.image  = cachedImg;
        CGFloat height = cachedImg.size.height;
        bigImgView.frame = CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, (height/cachedImg.size.width)*(SCREEN_WIDTH-30*displaywidth));
        nameLab.frame = CGRectMake(15*displaywidth, (height/cachedImg.size.width)*(SCREEN_WIDTH-30*displaywidth)+10*displaywidth, SCREEN_WIDTH-30*displaywidth, 35*displaywidth);
    }
    
}

- (void)downloadImage:(NSString *)imageURL forIndexPath:(NSIndexPath *)indexPath{
    __weak typeof(self) weakSelf = self;
    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageURL]
                                                          options:2
                                                         progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                                         }
                                                        completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
                                                            [[SDImageCache sharedImageCache] storeImage:image forKey:imageURL toDisk:YES];
                                                            [weakSelf performSelectorOnMainThread:@selector(reloadCellAtIndexPath:) withObject:indexPath waitUntilDone:NO];
                                                            
                                                        }];
}
- (void)reloadCellAtIndexPath:(NSIndexPath *)indexPath
{
    [_tableview reloadData];
}

- (NSString *)timeIntervalFromLastTime:(NSString *)lastTime lastTimeFormat:(NSString *)format1
{
    //上次时间
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
    dateFormatter1.dateFormat = format1;
    NSDate *lastDate = [dateFormatter1 dateFromString:lastTime];
    //当前时间
//    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init];
//    dateFormatter2.dateFormat = @"yyyy/MM/dd HH:mm:ss";
//    NSDate *currentDate = [dateFormatter2 dateFromString:currentTime];
    return [self timeIntervalFromLastTime:lastDate ToCurrentTime:[NSDate date]];
    
}
- (NSString *)timeIntervalFromLastTime:(NSDate *)lastTime ToCurrentTime:(NSDate *)currentTime
{
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    //上次时间
    NSDate *lastDate = [lastTime dateByAddingTimeInterval:[timeZone secondsFromGMTForDate:lastTime]];
    //当前时间
    NSDate *currentDate = [currentTime dateByAddingTimeInterval:[timeZone secondsFromGMTForDate:currentTime]];
    //时间间隔
    NSInteger intevalTime = [currentDate timeIntervalSinceReferenceDate] - [lastDate timeIntervalSinceReferenceDate];

    //秒、分、小时、天、月、年
    NSInteger minutes = intevalTime / 60;
    NSInteger hours = intevalTime / 60 / 60;
    NSInteger day = intevalTime / 60 / 60 / 24;
    NSInteger month = intevalTime / 60 / 60 / 24 / 30;
    NSInteger yers = intevalTime / 60 / 60 / 24 / 365;

    if (minutes <= 10)
    {
        return  @"刚刚";
    }
    else if (minutes < 60)
    {
        return [NSString stringWithFormat: @"%ld分钟前",(long)minutes];
    }
    else if (hours < 24)
    {
        return [NSString stringWithFormat: @"%ld小时前",(long)hours];
    }else if (day < 30)
    {
        return [NSString stringWithFormat: @"%ld天前",(long)day];
    }else if (month < 12)
    {
        return [NSString stringWithFormat: @"%ld月前",(long)month];
    }
    else if (yers >= 1){
        return [NSString stringWithFormat: @"%ld年前",(long)yers];
    }
    return @"";
}


- (void)showAction:(UIButton *)btn
{
    _detaModel.isShow = !_detaModel.isShow;
    [self.tableview reloadData];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *myView = [[UIView alloc] init];
    if (section == 0)
    {
        myView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 45*displayheight);
        myView.backgroundColor = [UIColor whiteColor];
        NSArray *titArray = @[@"公司地址",@"企业简介",@"企业相册"];
        if (_companyLineAry.count > 0)
        {
            titArray = @[@"公司地址",@"企业简介",@"线路价格",@"企业相册"];
        }
        CGFloat width = (SCREEN_WIDTH-3)/titArray.count;
        for (int i = 0; i < titArray.count; i++)
        {
            UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake((width+1)*i, 0, width, 44*displayheight) ImageName:nil Target:self Action:@selector(closeInfoAction:) Title:titArray[i] Font:16.0];
            btn.backgroundColor = [UIColor whiteColor];
            [btn setTitleColor:RGB(51, 51, 51) forState:UIControlStateNormal];
            if (i == _infoType)
            {
                [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
            }
            btn.tag = 20+i;
            [myView addSubview:btn];
            if (i != 3)
            {
                UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(width+(width+1)*i, 12.5*displayheight, 1, 20*displayheight)];
                lineview.backgroundColor = RGB(153, 153, 153);
                [myView addSubview:lineview];
            }
            
        }
        UIView *lineBV = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/(titArray.count)*_infoType, 44*displayheight, SCREEN_WIDTH/titArray.count, 1*displayheight)];
        lineBV.backgroundColor = ThemeColor;
        [myView addSubview:lineBV];
        lineBottomV = lineBV;
    }
    return myView;
}

- (void)closeInfoAction:(UIButton *)btn
{
    _infoType = btn.tag-20;
    NSInteger k = 3;
    if (_companyLineAry.count > 0)
    {
        k = 4;
    }
    if (btn.tag == 20)
    {
        //公司地址
    }
    else if (btn.tag == 21)
    {
        //企业介绍
    }
    else if (btn.tag == 22)
    {
        //线路价格
    }
    else
    {
        //企业相册
    }
    
    lineBottomV.frame = CGRectMake(SCREEN_WIDTH/k*_infoType, 44*displayheight, SCREEN_WIDTH/k, 1*displayheight);
    [self.tableview reloadData];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 45*displayheight;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_infoType == 0)
    {
        ServiceSiteModel *model = _serviceAry[indexPath.row];
        CGRect bounds = [model.address boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-100*displaywidth, 300) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
        if (bounds.size.height > 25*displaywidth)
        {
            return bounds.size.height+150*displaywidth;
        }
        else
        {
            return 170*displaywidth;
        }
      
        
        
       
    }
    else if (_infoType == 1)
    {
        if (_detaModel)
        {
//            CGRect bounds = [[NSString stringWithFormat:@"       %@",_detaModel.describes] boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30*displayheight, 20000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            CGFloat height = [self getSpaceLabelHeight:[NSString stringWithFormat:@"       %@",_detaModel.describes] withFont:NormalFontWithSize(15.0+fontScale) withWidth:SCREEN_WIDTH-30*displaywidth];
            return height+370*displaywidth;
        }
        return 500*displayheight;
        
    }
    else if (_infoType == 2 && _companyLineAry.count > 0)
    {
        if (indexPath.section == 0 && _vehicleLineAry.count > 0)
        {
            if (indexPath.row == 0)
            {
                return 150*displaywidth;
            }
            return 70*displaywidth;
        }
        else
        {
            if (indexPath.row == 0)
            {
                return 135*displaywidth;
            }
            return 85*displaywidth;
        }
    }
    else
    {
        CompanyImgModel *imgModel = _companyImgAry[indexPath.row];
        UIImage *img = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imgModel.img];
        if (!img) {
            return 195*displaywidth;
        }
        CGFloat height = img.size.height;
        return (height/img.size.width)*(SCREEN_WIDTH-30*displaywidth)+45*displaywidth;
    }
    return 120;
}

- (void)creatPingfen
{
    NSArray *imgAry = [_detaModel.photoImgs componentsSeparatedByString:@","];
    _cycleScrollView.imageURLStringsGroup = imgAry;
    titLab.text = [NSString stringWithFormat:@"主营：%@",_detaModel.sketch];
    UILabel *fenNumLab = [ZCControl createLabelWithFrame:CGRectMake(5*displaywidth, 0, 65*displayheight, 40*displayheight) Font:12.0 Text:[NSString stringWithFormat:@"%@\n综合信誉",_detaModel.avgRate] Color:RGB(102, 102, 102)];
    fenNumLab.numberOfLines = 0;
    fenNumLab.textAlignment = NSTextAlignmentCenter;
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:fenNumLab.text];
    NSRange range = NSMakeRange(0, _detaModel.avgRate.length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:RGB(255, 0, 0) range:range];
    [fenNumLab setAttributedText:noteStr];
    [cerView addSubview:fenNumLab];
    
    UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(71*displaywidth, 10*displayheight, 1, 20*displayheight)];
    lineview.backgroundColor = RGB(153, 153, 153);
    [cerView addSubview:lineview];
    CGFloat W = 80*displaywidth;
    if (_detaModel.isGongShang)
    {
        UILabel *gonLab = [ZCControl createLabelWithFrame:CGRectMake(W, 12.5*displayheight, 15*displaywidth, 15*displayheight) Font:10.0 Text:@"工" Color:[UIColor whiteColor]];
        gonLab.backgroundColor = RGB(32, 69, 139);
        gonLab.layer.cornerRadius = 2;
        gonLab.layer.masksToBounds = YES;
        gonLab.textAlignment = NSTextAlignmentCenter;
        [cerView addSubview:gonLab];
        W+=25*displaywidth;
    }
    if ([_detaModel.shi integerValue] == 1)
    {
        UILabel *shiLab = [ZCControl createLabelWithFrame:CGRectMake(W, 12.5*displayheight, 15*displaywidth, 15*displayheight) Font:10.0 Text:@"实" Color:[UIColor whiteColor]];
        shiLab.backgroundColor = RGB(255, 153, 0);
        shiLab.layer.cornerRadius = 2;
        shiLab.layer.masksToBounds = YES;
        shiLab.textAlignment = NSTextAlignmentCenter;
        [cerView addSubview:shiLab];
        W+=25*displaywidth;
    }
    if ([_detaModel.bao integerValue] == 1)
    {
        UILabel *baoLab = [ZCControl createLabelWithFrame:CGRectMake(W, 12.5*displayheight, 15*displaywidth, 15*displayheight) Font:10.0 Text:@"保" Color:[UIColor whiteColor]];
        baoLab.backgroundColor = RGB(0, 153, 255);
        baoLab.layer.cornerRadius = 2;
        baoLab.layer.masksToBounds = YES;
        baoLab.textAlignment = NSTextAlignmentCenter;
        [cerView addSubview:baoLab];
        W+=25*displaywidth;

    }
    CDZStarsControl *starsControl = [[CDZStarsControl alloc] initWithFrame:CGRectMake(W, 5*displayheight, 100*displaywidth , 30*displayheight) stars:5 starSize:CGSizeMake(20*displayheight, 20*displayheight) noramlStarImage:[UIImage imageNamed:@"star_normal"] highlightedStarImage:[UIImage imageNamed:@"star01"]];
    starsControl.delegate = self;
    starsControl.allowFraction = YES;
    starsControl.score = [_detaModel.avgRate floatValue];
    starsControl.isEntlab = NO;
    [cerView addSubview:starsControl];

    
    UIButton *credibilityBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, 185*displaywidth, 40*displaywidth) ImageName:nil Target:self Action:@selector(credibilityAction) Title:nil Font:12.0];
    credibilityBtn.backgroundColor = [UIColor clearColor];
    [cerView addSubview:credibilityBtn];
    
//    UILabel *pepLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-120*displaywidth, 12.5*displayheight, 90*displaywidth, 15*displayheight) Font:10.0 Text:[NSString stringWithFormat:@"%@人评论",_detaModel.commentCount] Color:RGB(102, 102, 102)];
//    pepLab.textAlignment = NSTextAlignmentRight;
//    [cerView addSubview:pepLab];
//    UIImageView *imgV = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-25*displaywidth, 15*displayheight, 10*displaywidth, 10*displayheight) ImageName:@"gs_icon05"];
//    imgV.contentMode = UIViewContentModeScaleAspectFit;
//    [cerView addSubview:imgV];
    NSInteger isCollect = [_detaModel.isCollect integerValue];
    NSString *titString = @" 收藏";
    BOOL k = NO;
    if (isCollect == 1)
    {
        titString = @" 已收藏";
        k = YES;
    }
    UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH- 90*displaywidth, 10*displayheight, 75*displaywidth, 20*displayheight) ImageName:@"gs_icon0311" Target:self Action:@selector(collectAction) Title:titString Font:11.0];
    btn.backgroundColor = ThemeColor;
    btn.layer.cornerRadius = 3;
    btn.layer.masksToBounds = YES;
    btn.selected = k;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    collectBtn = btn;
    [cerView addSubview:btn];
    
}

//综合信誉
- (void)credibilityAction
{
    CredibilityViewController *vc = [[CredibilityViewController alloc] init];
    vc.comPanyId = _comPanyId;
    [self.navigationController pushViewController:vc animated:YES];
}

//收藏
- (void)collectAction
{
    WEAKSELF;
    NSDictionary *dic = @{@"type":@"1",
                          @"joinId":_comPanyId};
    [HYBaseHandler requestWithTheFormUrl:SERVER_phoneBook Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSString *msg = s_str(obj[@"msg"]);
            if (![msg containsString:@"取消"])
            {
                [LTools showMBProgressWithText:@"收藏成功" addToView:weakSelf.view];
                [collectBtn setTitle:@"已收藏" forState:UIControlStateNormal];
            }
            else
            {
                [LTools showMBProgressWithText:@"取消收藏成功" addToView:weakSelf.view];
                [collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
            }
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)itemBtnAction:(UIButton *)btn
{
    if (btn.tag == 10)
    {
        //官网
        if ([_detaModel.url isEqualToString:@""])
        {
            [LTools showMBProgressWithText:@"该公司暂无官网" addToView:self.view];
            return;
        }
        H5PublicViewController *vc = [[H5PublicViewController alloc] init];
        vc.url = _detaModel.url;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    else if (btn.tag == 11)
    {
        //分享
        if (![LTools storageForKey:SERVER_IsLogin])
        {
            [LTools showMBProgressWithText:@"请先登录" addToView:self.view];
            return;
        }
        UserAccountModel *model = [UserAccountModel shareMange];
        ShareManager *manager = [ShareManager shareToManager];
        manager.title = @"专线网";
        manager.descriptionStr = [NSString stringWithFormat:@"%@,%@",_detaModel.companyName,_detaModel.describes];
        manager.imgUrl = @"logo3x60";
        manager.logoimgUrl = nil;
        if (logoimage)
        {
            manager.logoimgUrl = logoimage;
        }
        manager.webUrl = [NSString stringWithFormat:@"https://new.wuliu.xin/companyDetail?id=%@&inviteUserId=%ld",_comPanyId,model.ID];
        
    }
    else
    {
        //询价
        MakeInquiryViewController *vc = [[MakeInquiryViewController alloc] init];
        vc.companyID = _comPanyId;
        vc.typeStr = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }
}



- (void)pushMapAction:(UIButton *)btn
{
    NSInteger index = btn.tag-200;
    ServiceSiteModel *model = _serviceAry[index];
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    WEAKSELF;
    [alertVC addAction:[UIAlertAction actionWithTitle:@"用iPhone自带地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf pushIphoneMap:model];
    }]];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]])
    {
        [alertVC addAction:[UIAlertAction actionWithTitle:@"用百度地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([model.lat floatValue], [model.lng floatValue]);
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }]];
    }
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"用高德地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
                            {
                                CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([model.lat floatValue], [model.lng floatValue]);
                                NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",@"专线网",@"LogisticsUrl",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                                
                                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
                            }]];
    }
    
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)callPgoneAction:(UIButton *)btn
{
    NSInteger row = btn.tag/1000-1;
    NSInteger index = btn.tag%10;
    ServiceSiteModel *model = _serviceAry[row];
    _phoneName = model.stationName;
    if (index == 1)
    {
        _phoneString = model.phone;
        //业务咨询
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",model.phone]]];
    }
    else
    {
        _phoneName = [_phoneName stringByAppendingString:@"售后"];
        _phoneString = model.fixPhone;
        //售后电话
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",model.fixPhone]]];
    }

}

//公司详情
- (void)requestCompanySelect
{
    WEAKSELF;
    NSDictionary *dic = @{@"id":_comPanyId};
    [HYBaseHandler requestCompanySelectParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _detaModel = [DetailsModel mj_objectWithKeyValues:obj[@"data"]];
            self.navigationItem.title = _detaModel.companyName;
            if (_detaModel.logo.length > 0)
            {
                logoimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_detaModel.logo]]];
                [logoimage jkr_compressToDataLength:3200 withBlock:^(NSData *data) {
                    UIImage *imageOne = [UIImage imageWithData:data];
                    logoimage = imageOne;
                }];
            }
            if ([obj[@"data"] isKindOfClass:[NSString class]])
            {
                return;
            }
            if ([obj[@"data"][@"companyInfo"] isKindOfClass:[NSDictionary class]])
            {
                _cerModel = [certificationModel mj_objectWithKeyValues:obj[@"data"][@"companyInfo"]];
                _detaModel.isGongShang = YES;
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf creatPingfen];
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

//服务站点
- (void)requestStatioFindByCompany
{
    WEAKSELF;
    NSDictionary *dic = @{@"companyId":_comPanyId,
                          @"lng":[LTools cacheForKey:SERVER_longitude],
                          @"lat":[LTools cacheForKey:SERVER_latitude],
                          @"size":@"9999"
                          };
    [HYBaseHandler requestStatioFindByCompanyParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _serviceAry = [ServiceSiteModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

//企业相册
- (void)requestCompanyImg
{
    WEAKSELF;
    NSDictionary *dic = @{@"companyId":_comPanyId,
                          @"size":@"999"};
    [HYBaseHandler requestWithTheFormUrl:SERVER_companyImg Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _companyImgAry = [CompanyImgModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

//线路
- (void)requestCompanyLine
{
    WEAKSELF;
    NSDictionary *dic = @{@"company.id":_comPanyId,
                          @"size":@"999"};
    [HYBaseHandler requestWithTheFormUrl:SERVER_companyLine Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _companyLineAry = [ComLineModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                for (ComLineModel *model in _companyLineAry)
                {
                    if ([model.type integerValue] == 1)
                    {
                        [weakSelf.LCLLineAry addObject:model];
                    }
                    else
                    {
                        [weakSelf.vehicleLineAry addObject:model];
                    }
                }
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)pushIphoneMap:(ServiceSiteModel *)model
{
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]){
        //MKMapItem 使用场景: 1. 跳转原生地图 2.计算线路
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        
        //地理编码器
//        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        //我们假定一个终点坐标，上海嘉定伊宁路2000号报名大厅:121.229296,31.336956
//        [geocoder geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//            CLPlacemark *endPlacemark  = placemarks.lastObject;
//
//            //创建一个地图的地标对象
//            MKPlacemark *endMKPlacemark = [[MKPlacemark alloc] initWithPlacemark:endPlacemark];
//            //在地图上标注一个点(终点)
//            MKMapItem *endMapItem = [[MKMapItem alloc] initWithPlacemark:endMKPlacemark];
            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([model.lat floatValue], [model.lng floatValue]);
            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]];
            
            
            
            toLocation.name = @"目的地";
            //MKLaunchOptionsDirectionsModeKey 指定导航模式
            //NSString * const MKLaunchOptionsDirectionsModeDriving; 驾车
            //NSString * const MKLaunchOptionsDirectionsModeWalking; 步行
            //NSString * const MKLaunchOptionsDirectionsModeTransit; 公交
            [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                           launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
            
//        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
